<HTML><HEAD><TITLE>char_code(?Char, ?Code)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term Manipulation</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>char_code(?Char, ?Code)</H1>
Succeeds if Code is the numeric character code of the character Char.


<DL>
<DT><EM>Char</EM></DT>
<DD>One-character atom, string or variable.
</DD>
<DT><EM>Code</EM></DT>
<DD>Integer or variable.
</DD>
</DL>
<H2>Description</H2>
   If Char is instantiated to a one-character atom or string,
   Code is unified with the corresponding numeric character code,
   depending on the character encoding in use.

<P>
   If Code is instantiated to an integer, Char is unified with the
   corresponding one-character atom.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>char_code(+, -) is det
<LI>char_code(-, +) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(5) type error </EM>
<DD>Char is instantiated, but not to a 1-character string or atom.
<DT><EM>(5) type error </EM>
<DD>Code is instantiated, but not to an integer.
<DT><EM>(6) out of range </EM>
<DD>Code is instantiated to an integer outside the valid range for character codes.
<DT><EM>(4) instantiation fault </EM>
<DD>Neither Char nor Code are instantiated (non-coroutine mode only).
</DL>
<H2>Examples</H2>
<PRE>
   Success:
   char_code(b,98).
   char_code("b",98).
   char_code(C,99).     (gives C=c).
   char_code(a,I).      (gives I=97).
   Fail:
   char_code(a,98).
   Error:
   char_code(C,I).       (Error 4).
   char_code(ab,I).      (Error 5).
   char_code(7,I).       (Error 5).
   char_code(C,-1).      (Error 6).



</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/iochar/get_char-1.html">get_char / 1</A>, <A HREF="../../kernel/iochar/get_char-2.html">get_char / 2</A>, <A HREF="../../kernel/iochar/put_char-1.html">put_char / 1</A>, <A HREF="../../kernel/iochar/put_char-2.html">put_char / 2</A>, <A HREF="../../kernel/stratom/string_code-3.html">string_code / 3</A>, <A HREF="../../kernel/stratom/string_list-2.html">string_list / 2</A>, <A HREF="../../kernel/stratom/string_list-3.html">string_list / 3</A>
</BODY></HTML>
